package com.onec.service.api.dto.request.channel;

import com.onec.service.api.content.PatternUtil;
import com.onec.service.api.dto.request.gateway.BizContent;
import com.onec.service.api.enums.ServiceApiEnum;
import com.onec.service.api.utils.group.trade.ApiPayGroup;
import com.onec.service.api.utils.group.trade.HtmlPayGroup;
import com.onec.service.api.utils.group.trade.QueryGroup;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.math.BigDecimal;

/**
 * channle 订单请求处理！
 *
 * @author onec
 */
@Data
@EqualsAndHashCode(callSuper=false)
public class ChannelTradeReq {

    /**
     * (机构)商户号
     */
    @NotNull(message = "商户编号不可为空", groups = {HtmlPayGroup.class, QueryGroup.class})
    public String merchantNo;

    /**
     * 机构订单号
     */
    @NotNull(message = "机构订单号不可为空", groups = {HtmlPayGroup.class, QueryGroup.class})
    @Length(min = 8, max = 32, message = "机构订单号介于8-32之间", groups = {HtmlPayGroup.class})
    public String externalNum;

    /**
     * 通道订单号
     */
    public String tradeNum;

    /**
     * 平台流水号
     */

    public String serialNum;
    /**
     * 平台流水号
     */
    /**
     * 机构订单号
     */
    @NotNull(message = "服务编号不可为空", groups = {HtmlPayGroup.class, QueryGroup.class})
    public ServiceApiEnum serviceApiEnum;
    /**
     * 交易金额
     */
    @Pattern(regexp = PatternUtil.AMOUNT_, message = "交易金额不合法")
    @NotNull(message = "交易金额不可为空", groups = {HtmlPayGroup.class})
    public String amount;
    /**
     * 业务编号
     */
    @NotNull(message = "业务编号不可空", groups = {QueryGroup.class, HtmlPayGroup.class})
    @Length(min = 5, max = 32, message = "业务编码介于8-32之间", groups = {QueryGroup.class, HtmlPayGroup.class})
    public String businessNo;

    /**
     * 业务编号
     */
    @NotNull(message = "通道业务编号不可空", groups = {QueryGroup.class, HtmlPayGroup.class})
    @Length(min = 5, max = 32, message = "通道业务编号介于8-32之间", groups = {QueryGroup.class, HtmlPayGroup.class})
    public String channelBusinessNo;

    /**
     * 机构订单号
     */
    @NotNull(message = "手机号不可为空", groups = {HtmlPayGroup.class})
    @Pattern(regexp = PatternUtil.PHONE, message = "手机信息不合法", groups = {})
    public String phone;


    /**
     * 银行卡号
     */
    @NotNull(message = "银行卡号不可为空", groups = {HtmlPayGroup.class})
    public String cardNo;
    /**
     * 姓名
     */
    @Pattern(regexp = PatternUtil.REG_NAME, message = "姓名格式有误", groups = {HtmlPayGroup.class})
    public String userName;
    /**
     * 身份信息
     */
    @Pattern(regexp = PatternUtil.REG_ID_CARD,
            message = "身份信息不合法", groups = {HtmlPayGroup.class})
    public String idCard;

    /**
     * 交易金额
     */
    @Pattern(regexp = PatternUtil.REG_URL, message = "同步回调地址URL不合法")
    public String frontUrl;

    @Pattern(regexp = PatternUtil.REG_URL, message = "异步回调地址URL不合法", groups = {HtmlPayGroup.class})
    @NotNull(message = "异步通知地址不可为空", groups = {HtmlPayGroup.class})
    public String callBackUrl;
    /**
     * 产品信息
     */
    public String productInfo;

    @NotNull(message = "城市编码不可为空", groups = {ApiPayGroup.class})
    public String city;

    public String mcc;

    @NotNull(message = "异步通知地址不可为空", groups = {HtmlPayGroup.class})
    public String product;
    /**
     * 代理编号
     */
    public String agentNo;
    /**
     * 代理编号
     */
    public String channelNo;
    /**
     * 当前商户交易费率：
     */
    public BigDecimal merchantRate;
    /**
     * 当前商户D1费率
     */
    public BigDecimal merchantFee;


    public ChannelTradeReq() {
    }

    /**
     * 交易风控信息
     *
     * @param bizContent
     * @param
     */
    public ChannelTradeReq(BizContent bizContent) {
        this.businessNo = bizContent.getBusinessNo();
        this.merchantNo = bizContent.getMerchantNo();
        this.agentNo = bizContent.getAgentNo();
        this.amount = bizContent.getAmount();
        this.cardNo = bizContent.getCardNo();
        this.product = bizContent.getProduct();
        this.idCard = bizContent.getIdCard();
        this.phone = bizContent.getPhone();
    }


}
